#include<stdio.h>
#include<unistd.h>
#include<pthread.h>

pthread_mutex_t mutex;
pthread_cond_t cond;
void* Routine(void* arg)
{
  pthread_detach(pthread_self());
  printf("%s run...\n",(char*)arg);
  while(1)
  {
    pthread_cond_wait(&cond,&mutex);
    printf("%s 活动...\n",(char*)arg);
  }
}

int main()
{

  pthread_t t1,t2,t3;
  pthread_mutex_init(&mutex,NULL);
  pthread_cond_init(&cond,NULL);

  pthread_create(&t1,NULL,Routine,(void*)"thread 1");
  pthread_create(&t2,NULL,Routine,(void*)"thread 2");
  pthread_create(&t3,NULL,Routine,(void*)"thread 3");
  while(1)
  {
    getchar();
    pthread_cond_broadcast(&cond);
  }
  pthread_mutex_destroy(&mutex);
  pthread_cond_destroy(&cond);
  return 0;
}
